package com.lifp.controller;

import com.lifp.entity.TbArticle;
import com.lifp.service.TbArticleService;
import com.lifp.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description TODO
 * @Author lfp
 * @Date 2022/8/12
 * @Version 1.0
 */
@RestController
@RequestMapping("article")
@Api(tags = "文章管理")
public class ArticleController {
    @Autowired
    private TbArticleService tbArticleService;

    @ApiOperation("列表查询")
    @GetMapping("list")
    @PreAuthorize("hasAuthority('SystemContent')")
    public Result<List<TbArticle>> list(){
        return Result.ok(tbArticleService.list());
    }

    @ApiOperation("根据编号查询")
    @GetMapping("selectOne/{id}")
    @PreAuthorize("hasAuthority('SystemContentView')")
    public Result<TbArticle> selectOne(@PathVariable String id){
        return Result.ok(tbArticleService.getById(id));
    }

    @ApiOperation("删除")
    @GetMapping("delete/{id}")
    @PreAuthorize("hasAuthority('SystemContentDelete')")
    public Result delete(@PathVariable String id){
        return Result.ok(tbArticleService.removeById(id));
    }

}
